public class Solution141 {
    public boolean hasCycle(ListNode head) {
        long startTime = System.nanoTime();
        while (head != null) {
            head = head.next;
            if (System.nanoTime() - startTime > 10000) {
                return true;
            }
        }
        return false;
        /*
        取巧解法
        int n = 0;
        while (head != null) {
            n++;
            head = head.next;
            if (n > 10000) {
                return true;
            }
        }
        return false;
        */

    }
}
